package cn.minhx.lab.design_patterns.adapter.f2.fields;

import cn.minhx.lab.design_patterns.adapter.f2.fields.message.CreateAccountMessage;
import cn.minhx.lab.design_patterns.adapter.f2.fields.message.OrderMessage;
import com.alibaba.fastjson2.JSON;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

public class Test {

    public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
        // 1 开户消息
        CreateAccountMessage createAccountMessage = new CreateAccountMessage();
        createAccountMessage.setNumber("10001");
        createAccountMessage.setAddress("福建省 厦门市 集美区 杏林湾");
        createAccountMessage.setAccountDate(LocalDate.now());
        createAccountMessage.setDesc("开户");

        Map<String, String> link01 = new HashMap<>();
        link01.put("userId", "number");
        link01.put("bizId", "number");
        link01.put("bizTime", "accountDate");
        link01.put("desc", "desc");

        CommonMessage commonMessage = MessageAdapter.filter(JSON.toJSONString(createAccountMessage), link01);
        System.out.println();
        System.out.println("createAccountMessage = " + JSON.toJSONString(createAccountMessage));
        System.out.println("commonMessage = " + JSON.toJSONString(commonMessage));

        System.out.println("------------------------------------分割线-------------------------------------------------");

        // 2 下单消息
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setUid("10002");
        orderMessage.setSku("100026559400001");
        orderMessage.setOrderId("10000777777");
        orderMessage.setOrderCreateDate(LocalDate.now());

        Map<String, String> link02 = new HashMap<>();
        link02.put("userId", "uid");
        link02.put("bizId", "orderId");
        link02.put("bizTime", "orderCreateDate");
        CommonMessage commonMessage2 = MessageAdapter.filter(JSON.toJSONString(orderMessage), link02);
        System.out.println("orderMessage = " + JSON.toJSONString(orderMessage));
        System.out.println("commonMessage2 = " + JSON.toJSONString(commonMessage));
        System.out.println();

    }

}
